

package com.thxrinfo.stop.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pig4cloud.pig.common.core.util.R;
import com.pig4cloud.pig.common.log.annotation.SysLog;
import com.thxrinfo.stop.api.entity.ReportHoliday;
import com.thxrinfo.stop.service.ReportHolidayService;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.*;


/**
 * 节假日维护
 *
 * @author silencezheng
 * @date 2023-02-25 17:18:19
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/reportholiday" )
@Tag(name = "节假日维护管理")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class ReportHolidayController {

    private final  ReportHolidayService reportHolidayService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param reportHoliday 节假日维护
     * @return
     */
    @Operation(summary = "分页查询", description = "分页查询")
    @GetMapping("/page" )
    @PreAuthorize("@pms.hasPermission('stop_reportholiday_get')" )
    public R getReportHolidayPage(Page page, ReportHoliday reportHoliday) {
        return R.ok(reportHolidayService.page(page, Wrappers.query(reportHoliday)));
    }


    /**
     * 通过id查询节假日维护
     * @param id id
     * @return R
     */
    @Operation(summary = "通过id查询", description = "通过id查询")
    @GetMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('stop_reportholiday_get')" )
    public R getById(@PathVariable("id" ) Long id) {
        return R.ok(reportHolidayService.getById(id));
    }

    /**
     * 新增节假日维护
     * @param reportHoliday 节假日维护
     * @return R
     */
    @Operation(summary = "新增节假日维护", description = "新增节假日维护")
    @SysLog("新增节假日维护" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('stop_reportholiday_add')" )
    public R save(@RequestBody ReportHoliday reportHoliday) {
        return R.ok(reportHolidayService.save(reportHoliday));
    }

    /**
     * 修改节假日维护
     * @param reportHoliday 节假日维护
     * @return R
     */
    @Operation(summary = "修改节假日维护", description = "修改节假日维护")
    @SysLog("修改节假日维护" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('stop_reportholiday_edit')" )
    public R updateById(@RequestBody ReportHoliday reportHoliday) {
        return R.ok(reportHolidayService.updateById(reportHoliday));
    }

    /**
     * 通过id删除节假日维护
     * @param id id
     * @return R
     */
    @Operation(summary = "通过id删除节假日维护", description = "通过id删除节假日维护")
    @SysLog("通过id删除节假日维护" )
    @DeleteMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('stop_reportholiday_del')" )
    public R removeById(@PathVariable Long id) {
        return R.ok(reportHolidayService.removeById(id));
    }

}
